package com.shikong.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shikong.blog.common.Response;
import com.shikong.blog.domain.dos.BlogMineDO;
import com.shikong.blog.domain.dos.BlogSettingDO;
import com.shikong.blog.domain.mapper.BlogMineMapper;
import com.shikong.blog.model.systemvo.blogsetting.QueryBlogMineRspVO;
import com.shikong.blog.model.systemvo.blogsetting.QueryBlogSettingRspVO;
import com.shikong.blog.model.systemvo.blogsetting.UpdateBlogMineReqVO;
import com.shikong.blog.service.AdminBlogMineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @Description: TODO
 * @Version: 1.0
 */
@Service
@Slf4j
public class AdminBlogMineServiceImpl extends ServiceImpl<BlogMineMapper, BlogMineDO> implements AdminBlogMineService {

    @Autowired
    BlogMineMapper blogMineMapper;

    @Override
    public Response updateBlogMine(UpdateBlogMineReqVO updateBlogMineReqVO) {
        BlogMineDO blogMineDO = BlogMineDO.builder()
                .id(1L)
                .pictureOne(updateBlogMineReqVO.getPictureOne())
                .textOne(updateBlogMineReqVO.getTextOne())
                .textTwo(updateBlogMineReqVO.getTextTwo())
                .pictureTwo(updateBlogMineReqVO.getPictureTwo())
                .textThree(updateBlogMineReqVO.getTextThree())
                .textFour(updateBlogMineReqVO.getTextFour())
                .pictureThree(updateBlogMineReqVO.getPictureThree())
                .textFive(updateBlogMineReqVO.getTextFive())
                .textSix(updateBlogMineReqVO.getTextSix())
                .pictureFour(updateBlogMineReqVO.getPictureFour())
                .textSeven(updateBlogMineReqVO.getTextSeven())
                .build();
        saveOrUpdate(blogMineDO);
        return Response.success();
    }

    @Override
    public Response queryBlogMineDetail() {
        BlogMineDO blogMineDO = getOne(null);

        QueryBlogMineRspVO queryBlogMineRspVO = null;
        if (Objects.nonNull(blogMineDO)) {
            queryBlogMineRspVO = QueryBlogMineRspVO.builder()
                    .id(blogMineDO.getId())
                    .pictureOne(blogMineDO.getPictureOne())
                    .textOne(blogMineDO.getTextOne())
                    .textTwo(blogMineDO.getTextTwo())
                    .pictureTwo(blogMineDO.getPictureTwo())
                    .textThree(blogMineDO.getTextThree())
                    .textFour(blogMineDO.getTextFour())
                    .pictureThree(blogMineDO.getPictureThree())
                    .textFive(blogMineDO.getTextFive())
                    .textSix(blogMineDO.getTextSix())
                    .pictureFour(blogMineDO.getPictureFour())
                    .textSeven(blogMineDO.getTextSeven())
                    .build();
        }
        return Response.success(queryBlogMineRspVO);
    }
}